<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise关键问题 - Promise 对象状态改变的方式</title>
</head>
<body>
    <script>

        /**
         *   如何改变 promise 的状态?
         *   (1) resolve(value): 如果当前是 pending 就会变为 resolved
         *   (2) reject(reason): 如果当前是 pending 就会变为 rejected
         *   (3) 抛出异常: 如果当前是 pending 就会变为 rejected
         */

        //没有调用resolve和reject前状态为pending
        let p =new Promise((resolve,reject)=>{

            //1.resolve函数  pending => fulfilled (resolved)
            //resolve('ok');

            //2.reject函数   pending => rejected
            //reject('error'); 

            //3.抛出错误 pending => rejected
            throw '出问题了!';
        });

        console.log(p);
    </script>
</body>
</html>